class Solution(object):
    def isHappy(self, n):
        """
        :type n: int
        :rtype: bool
        """
        already_set = {n}
        sum = n
        while True:
            n = sum
            sum = 0
            while n > 0:
                sum += (n % 10) ** 2
                n = n // 10
            if sum == 1:
                return True
            if sum in already_set:
                return False
            else:
                already_set.add(sum)



data = Solution()
n = 1
print(data.isHappy(n))